package com.d6game.web.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.ClassPathResource;

public class ConfigManager {

	private Log logger = LogFactory.getLog(ConfigManager.class);
	private HashMap<String,String> map = new HashMap<String,String>();  
	private static ConfigManager manager = new ConfigManager();	
	
	private ConfigManager(){
		try{
			ClassPathResource resource = new ClassPathResource("6dgame.properties");
			Properties properties = new Properties() ;
			properties.load(resource.getInputStream());
			Set<Object> keySet = properties.keySet();
			Iterator<Object> ite = keySet.iterator();
			while(ite.hasNext()){
				String key = ite.next().toString();
				map.put(key, properties.getProperty(key));
			}				
		}
		catch(Exception e){
			logger.error(e.getMessage(), e);
		}		
	}
	
	
	public static ConfigManager getInstance(){
		return manager;		
	}
	
	public String getConfig(String key){
		return map.get(key);
	}
	
}
